#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <sys/wait.h>

int main()
{
    int fd = open("temp", O_CREAT | O_RDWR, 0664);
    int len = 4096;
    ftruncate(fd, len);
    void* ptr = mmap(NULL, len, PROT_WRITE | PROT_READ, MAP_SHARED, fd, 0);
    if (ptr == MAP_FAILED)
    {
        perror("mmap");
        exit(1);
    }
    while(1)
    {
        sleep(2);
        //printf("%s\n", (char*)ptr);
        strcpy(ptr, "hello world hhhh\n");
    }
    int ret = munmap(ptr, len);
    if (ret == -1)
    {
        perror("munmap");
        exit(1);
    }
    
    return 0;
}
